<template>
  <div class="AnnouncementList">
    <div class="title">
      <span></span>
      <span>资讯</span>
    </div>
    <div class="subhead">
      <h3>{{data.title}}</h3>
      <span>{{data.createTime}}</span>
    </div>
    <div class="content" id="newsContent">
      <video controls name="media" v-if="flag && !isImg">
        <source :src="data.content" type="video/mp4">
      </video>
      <img :src="data.content" v-if="flag && isImg">
      {{flag ?'':data.content}}
      {{flag}}
      {{isImg}}
    </div>
  </div>
</template>
<script>
import $ from "jquery";
// import jwplayer from "../../jwplayer.js";

export default {
  data () {
    return {
      data: "",
      flag: false,
      isImg: false
    };
  },
  created () {
    this.$route.params.id == 0 || this.$route.params.id
      ? localStorage.setItem("id", this.$route.params.id)
      : "";
    u.newsDetails(
      {
        id: this.$route.params.id || localStorage.getItem("id")
      },
      data => {
        console.log(data.data)
        if (data && data.code == 200) {
          this.data = data.data;
          if(this.data.content.includes("embed")){
            this.data.content = this.data.content
            .replace('src="', 'src="' + u.imgurl)
            .replace('src="', "*");
            if (this.data.content.includes("http")) {
              this.flag = true;
              if (this.data.content.includes("img")) {
                this.isImg = true;
              }
            } else {
              return
            }
            let index = this.data.content.indexOf("*");
            let last = this.data.content.indexOf('"', index);
            this.data.content = this.data.content
              .substring(index, last)
              .replace("*", "");
          }else if(this.data.content.match(/<img[^>]*>/gi) != null && this.data.content.match(/<img[^>]*>/gi).length == 1){
            var str=this.data.content.match(/<img[^>]*>/gi);
            for(var i=0;i<str.length;i++){
              this.data.content=str[i].replace('src="', 'src="' + u.imgurl)
              $('#newsContent').html(this.data.content)
            }
          }else{
            $('#newsContent').html(this.data.content)
          }
        }
      }
    );
  },
  mounted () {
    // this.getVideo();
  },
  methods: {
    // getVideo() {
    //   $(document).ready(function(e) {
    //     setTimeout(function() {
    //       jwplayer.key = "hTHv8+BvigYhzJUOpkmEGlJ7ETsKmqyrQb8/PetBTBI=";
    //       //非视频，不加载播放器 ?
    //       if (document.getElementById("player") != null) {
    //         jwplayer("player").onReady(function() {});
    //         jwplayer("player").onPlay(function() {});
    //         jwplayer("player").play();
    //       }
    //       var src =
    //         document.getElementById("player") !== null
    //           ? document.getElementById("player").getAttribute("src")
    //           : "";
    //       jwplayer("player").setup({
    //         file: src,
    //         image: "http://52.79.71.169/ChainManagement/upload/1540546033165.jpg" //此处放视频封面图片
    //         // primary: "flash" ? ? ? //360极速模式不支持，会报错！?
    //       });
    //     }, 2000);
    //   });
    // },
  }
};
</script>

<style lang="less" scoped>
.AnnouncementList {
  height: 100%;
  overflow: auto;
  background: white;

.title {
  height: 50px;
  line-height: 50px;
  font-size: 16px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  border-bottom: 1px solid #f4f5f6;

span:nth-child(1) {
  margin: 0px 10px 0px 20px;
  margin-left: 20px;
  line-height: 50px;
  background: #ffb001;
  width: 5px;
  height: 18px;
  display: inline-block;
}

}
.subhead {
  padding: 30px 0px 42px 0px;
  text-align: center;

h3 {
  font-size: 20px;
  font-weight: normal;
  margin-bottom: 18px;
}

span {
  color: #999999;
  font-size: 14px;
}

}
.content {
  /*border: 1 px solid #000;*/
  padding: 0px 30px;
  text-align: center;
}

}
</style>
